﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WF_AttachMent_menu.aspx.vb"
    Inherits="MyWorkflow.WF_AttachMent_menu" EnableViewState="false" %>

<html>
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/_common/styles/global.css">

    <script language="javascript" src="/_controls/upfile/UpFile.js"></script>

    <script language="javascript" src="WF_AttachMent_Word.js"></script>
    
    <script language="javascript" src="/PubProject/js/Public.js"></script>
    
    <script language="javascript" src="workflow.js"></script>
    
    <script language="javascript" src="/_common/scripts/global.js"></script>

    <script type="text/javascript">
    
    //上传文档
	function upFile()
	{
	    var sFkGUID = document.getElementById("__FKGUID").value;
 	    var sTitle = "上传文档"; 
        var sWidth = "500px";
        var sHeight = "220px"; 	
        var sFile = "/_controls/upfile/UpFile_Main_Edit.aspx";    
        
        var sParamList = escape("FkGUID"); 
        sParamList += "=" + escape(sFkGUID); 
        sParamList += "&" + escape("sTitle"); 
        sParamList += "=" + escape(sTitle); 	
        sParamList += "&" + escape("DocType"); 
        sParamList += "=" + escape("工作流"); 
        sParamList += "&" + escape("PageState"); 
        sParamList += "=" + escape("EDIT"); 
        
        var ReturnValue = __OpenModalWinUpFile(sTitle,sFile,sParamList,sWidth,sHeight);
        if(ReturnValue=="ok"){
            window.location.reload();
        }
	}
    
    window.onload = function(){
        try{
            window.parent.dyniframesize();
            if(window.parent.document.getElementById("__mode").value == "3"){
                document.getElementById("aUpFile").style.display = "none";
            }else if(window.parent.document.getElementById("__mode").value == "2" && (window.parent.appForm.HandleType.value == "[抄送]" || (window.parent.appForm.NodeStatus.value != "1" && window.parent.appForm.NodeStatus.value != "2"))){
                document.getElementById("aUpFile").style.display = "none";
            }
        }catch(e){
            document.getElementById("aUpFile").style.display = "none";
        }
    }
        
    //功能：签入
    function checkin(oid,bAlert)
    {
	    if(bAlert==undefined) bAlert=true;
    	
	    var sResult = GetDataFromXMLHTTP("/MyWorkflow/WF_XmlHTTP.aspx","AttachMentDocCheckIn","",oid,"");
	    if(sResult=="-1") return false;
    	
	    var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
    	
	    xmlDom.loadXML(sResult);
    		
	    if(xmlDom.documentElement.attributes.getNamedItem("result").value == "true" )
	    {
		    return true;
	    }
	    else
	    {
		    if(bAlert) alert("签入失败，文档可能已被签入！");
		    return false;
	    }
    }

    //功能：签出
    function checkout(oid)
    {
	    var sResult = GetDataFromXMLHTTP("/MyWorkflow/WF_XmlHTTP.aspx","AttachMentDocCheckOut",window.parent.document.getElementById("__oid").value,oid,"");

	    if(sResult=="-1") return false;
    	
	    var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
    	
	    xmlDom.loadXML(sResult);
    	
	    if(xmlDom.documentElement.attributes.getNamedItem("result").value == "true" )
	    {
		    return 1;
	    }
	    else if(xmlDom.documentElement.attributes.getNamedItem("result").value == "already") 
	    {
		    return 0;
	    }
	    else
	    {
		    alert(xmlDom.documentElement.attributes.getNamedItem("errmessage").value);
		    return -1;
	    }
    }
    
    function oprEdit(o)
	{

		
		var sUrl = "WF_AttachMent_Word.aspx?mode="
		sUrl += "2";
		//CanDocComment
		sUrl += "&canDocComment=" + parent.appForm.CanDocComment.value;
		//CanDocModify
		sUrl += "&canDocModify=" + parent.appForm.CanDocModify.value;
			//CanDocFinalize
		sUrl += "&canDocFinalize=" + (parent.appForm.HandleType.value == "[协商]"?"0":parent.appForm.CanDocFinalize.value);
		
		sUrl += "&oid=" + o.oid
		sUrl += "&docname=" + escape(o.docname);
		sUrl += "&NodeGUID=" + escape(window.parent.document.getElementById("__oid").value);
		openMyFullWin(sUrl);
	}
    
    //功能：判断签出状态,生成菜单项
    function createMenuItem(oid)
    {
	    var sResult = GetDataFromXMLHTTP("/MyWorkflow/WF_XmlHTTP.aspx","IsAttachMentCheckOut","",oid,"");
	    if(sResult=="-1") return false;
    	
	    var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
    	
	    xmlDom.loadXML(sResult);
    	
	    if(xmlDom.documentElement.attributes.getNamedItem("result").value == "true" )
	    {
		    return "1011111";
	    }
	    else
	    {
		    return "1100001";
	    }
    }
    </script>

</head>
<body style="margin: 0px; background-color:White;" oncontextmenu="window.event.returnValue = false">
    <form id="form1" runat="server">
    <input id="__isallowopenfile" type="hidden" value="true" />
    <table width="100%" style="margin-top: 5px; margin-left: 8px">
        <tr>
            <td>
                <span><font style="font-size: 12px"><strong>审批附件</strong></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a id="aUpFile" href="#" onclick="upFile()">上传</a></span>
                <div id="menuForm" style="margin: 0px; padding: 2px 2px 2px 20px">
                    <asp:Repeater ID="rp" runat="server">
                        <HeaderTemplate>
                            <table width="80%">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td width="50%">
                                    <img src="/_imgs/ico_16_1039_d.gif">
                                    <a href="#" oncontextmenu="showMenu(this)" title="<%# Eval("DocName")%>" onclick="showMenu(this)" oid="<%# Eval("DocGUID") %>" docname="<%# Eval("DocName")%>"
                                    filename="<%# Eval("FileName") %>" createby="<%# Eval("UserName") %>" modifieduser="<%# Eval("modifieduser") %>"
                                    modifiedtime="<%# Eval("ModifiedDateTime") %>" createon="<%# Eval("CreateOn") %>" lockedby="<%# Eval("LockedBy") %>" lockeduser="<%# Eval("LockedUser") %>"><%#Eval("DocName1")%></a>
                                </td>
                        </ItemTemplate>
                        <AlternatingItemTemplate>
                            <td width="50%" noWrap>
                                <img src="/_imgs/ico_16_1039_d.gif">
                                <a href="#" oncontextmenu="showMenu(this)" title="<%# Eval("DocName")%>" onclick="showMenu(this)" oid="<%# Eval("DocGUID") %>" docname="<%# Eval("DocName")%>"
                                filename="<%# Eval("FileName") %>" createby="<%# Eval("UserName") %>" modifieduser="<%# Eval("modifieduser") %>"
                                modifiedtime="<%# Eval("ModifiedDateTime") %>" createon="<%# Eval("CreateOn") %>" lockedby="<%# Eval("LockedBy") %>" lockeduser='<%# Eval("LockedUser") %>'><%#Eval("DocName1")%></a>
                            </td>
                            </tr>
                        </AlternatingItemTemplate>
                        <FooterTemplate>
                            </table></FooterTemplate>
                    </asp:Repeater>
                </div>
            </td>
        </tr>
    </table>
    <!-- 这里用来定义需要显示的右键菜单 -->
    <div id="itemMenu" style="display: none;">
        <table border="0" width="100%" height="100%" bgcolor="#FFFFFF" style="font-size: 12px;
            border: 1 solid black;" cellspacing="0">
            <tr>
                <td width="5px">
                </td>
                <td align="left" style="padding-top: 2px;" action="select">
                    查看
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align="left" action="checkOut">
                    签出
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align="left" action="edit">
                    编辑
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align="left" action="checkIn">
                    签入
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align="left" action="rename">
                    重命名
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align="left" action="del">
                    删除
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align="left" action="attribute">
                    <span style="float: left">属性 </span><span style="float: right; vertical-align: middle;">
                        <img id="imgA" src="images/nav0_arrow_right.gif" /></span>
                </td>
            </tr>
        </table>
    </div>
    <div id="divAttribute" style="display:none;">
        <table border="0" width="100%" height="100%" bgcolor="#FFFFFF" style="font-size: 12px;border: 1 solid black;" cellspacing="0">
            <tr>
                <td>修改人：</td>
                <td></td>
            </tr>
            <tr>
                <td>修改时间：</td>
                <td></td>
            </tr>
            <tr>
                <td>创建人：</td>
                <td></td>
            </tr>
            <tr>
                <td>创建时间：</td>
                <td></td>
            </tr>
        </table>
    </div>
    <!-- 右键菜单结束-->

    <script type="text/javascript">

function menuclick(o,str)
{
    var reV;
    switch(str){
        case "select":
           __DownUpFile_FZ(o.docname,o.filename,"_blank");
            break;
        case "checkOut":
            checkout(o.oid);
            break;
        case "edit":
            oprEdit(o);
            break;
        case "checkIn":
            checkin(o.oid,true);
            break;
        case "rename":
            reV = __OpenModalWinUpFile("文档更名","/MyWorkflow/DocumentRename.aspx","oid="+escape(o.oid)+"&docname="+escape(o.docname),"400px","150px");
            if(reV != "" && reV != undefined ){
                 window.location.reload();
            }
            break;
        case "del":
            //if(confirm("您确定要删除文档 " + o.docname + " 吗？")){
            if(confirm("删除文档记录的同时会将已上传的对应文件也删除，是否继续？")){
                reV = GetDataFromXMLHTTP("/MyWorkflow/WF_XmlHTTP.aspx","DeleteUpFile",o.oid,"","");
                if(reV){
                    window.location.reload();
                }
            }
            break;
        case "attribute":
            showAttribute(o);            
            break;
    }
}
var x=0,y=0;
var pop,pop1;
var menuItem;
function showAttribute(obj){
    
    var divA = document.getElementById("divAttribute");
    var rowObjs = divA.getElementsByTagName("td");
    rowObjs[1].innerText = obj.modifieduser;
    rowObjs[3].innerText = obj.modifiedtime;
    rowObjs[5].innerText = obj.createby;
    rowObjs[7].innerText = obj.createon;

    pop1 = pop.document.parentWindow.createPopup();
    
    pop1.document.body.innerHTML = divA.innerHTML;
     
    pop1.document.oncontextmenu=function()
    {
       return false;
    }
    pop1.document.onclick=function()
    {
       pop1.hide();
    }
    //alert(x+"_"+y);
    pop1.show("0","0","200","75",pop.document.body);
    
}

function showMenu(obj)
{
    if(document.getElementById("aUpFile").style.display == "none"){
        menuItem = "1000001";
    }else{
        var mode = window.parent.document.getElementById("__mode").value;
        switch(mode){
            case "1":
                menuItem = "1000111";
                break;
            case "2":
                menuItem = createMenuItem(obj.oid);
                break;
            case "3":
                menuItem = "1000001";
                break;
        }
    }
    
    if(document.getElementById("aUpFile").style.display == "none"){
        menuItem = "1000001";
    }
    
    popMenu(itemMenu,80,menuItem,obj);
    event.returnValue=false;
    event.cancelBubble=true;
    return false;
}
/***显示弹出菜单
*menuDiv:右键菜单的内容
*width:行显示的宽度
*rowControlString:行控制字符串，0表示不显示，1表示显示，如“101”，则表示第1、3行显示，第2行不显示*/
function popMenu(menuDiv,width,rowControlString,obj)
{
    //创建弹出菜单
    pop=window.createPopup();

    //设置弹出菜单的内容
    pop.document.body.innerHTML=menuDiv.innerHTML;

    var rowObjs=pop.document.body.all[0].rows;

    //获得弹出菜单的行数
    var rowCount=rowObjs.length;

    //循环设置每行的属性
    for(var i=0;i<rowObjs.length;i++)
    {
        //如果设置该行不显示，则行数减一
        var hide=rowControlString.charAt(i)!='1';
        //设置是否显示该行
        //rowObjs[i].style.display=(hide)?"none":"";
        rowObjs[i].cells[1].style.color = hide?"#C5C5C5":"black";
        
        //设置鼠标滑入该行时的效果
        rowObjs[i].cells[1].onmouseover=function()
        {
            this.style.background="#B5BED6";
            this.style.cursor = "hand";
        }
        
        //设置鼠标滑出该行时的效果
        rowObjs[i].cells[1].onmouseout=function(){
            this.style.background="#FFFFFF";
            this.style.cursor = "hand";
        }
        
        if(!hide){
            if(rowObjs[i].cells[1].action != "attribute"){
                rowObjs[i].cells[1].onclick = function()
                {
                    menuclick(obj,this.action);
                }
            }else{
                rowObjs[i].cells[1].onmouseover = function()
                {
                    menuclick(obj,this.action);
                    this.style.background="#B5BED6";
                    this.style.cursor = "hand";
                }
                rowObjs[i].cells[1].onmouseout=function(){
                    pop1.hide();
                    this.style.background="#FFFFFF";
                    this.style.cursor = "hand";
                    //pop.hide();
                 }
            }
        }
    }
    //屏蔽菜单的菜单
    pop.document.oncontextmenu=function()
    {
       return false;
    }
    //选择右键菜单的一项后，菜单隐藏
    pop.document.onclick=function()
    {
        pop.hide();
        //document.getElementById("divAttribute").style.display = "none";
    }
    
    //显示菜单
    x = width;
    y = (rowCount-1)*22 + 2;
    pop.show(event.clientX+8,event.clientY,width,rowCount*22,document.body);
    return true;
}
    </script>

    </form>
</body>
</html>